home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / MouseCursors / MouseCursors.cs next >
Encoding:
Text File  |  2002-04-18  |  3.2 KB  |  79 lines

  1. //-------------------------------------------
  2. // MouseCursors.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class MouseCursors: Form
  9. {
  10.      Cursor[] acursor = 
  11.      { 
  12.           Cursors.AppStarting, Cursors.Arrow,       Cursors.Cross,       
  13.           Cursors.Default,     Cursors.Hand,        Cursors.Help,     
  14.           Cursors.HSplit,      Cursors.IBeam,       Cursors.No,          
  15.           Cursors.NoMove2D,    Cursors.NoMoveHoriz, Cursors.NoMoveVert,
  16.           Cursors.PanEast,     Cursors.PanNE,       Cursors.PanNorth,    
  17.           Cursors.PanNW,       Cursors.PanSE,       Cursors.PanSouth,
  18.           Cursors.PanSW,       Cursors.PanWest,     Cursors.SizeAll,     
  19.           Cursors.SizeNESW,    Cursors.SizeNS,      Cursors.SizeNWSE,
  20.           Cursors.SizeWE,      Cursors.UpArrow,     Cursors.VSplit,      
  21.           Cursors.WaitCursor
  22.      };
  23.      string[] astrCursor = 
  24.      { 
  25.           "AppStarting",       "Arrow",             "Cross",       
  26.           "Default",           "Hand",              "Help",     
  27.           "HSplit",            "IBeam",             "No",          
  28.           "NoMove2D",          "NoMoveHoriz",       "NoMoveVert",
  29.           "PanEast",           "PanNE",             "PanNorth",    
  30.           "PanNW",             "PanSE",             "PanSouth",
  31.           "PanSW",             "PanWest",           "SizeAll",     
  32.           "SizeNESW",          "SizeNS",            "SizeNWSE",
  33.           "SizeWE",            "UpArrow",           "VSplit",      
  34.           "WaitCursor" 
  35.      };
  36.  
  37.      public static void Main()
  38.      {
  39.           Application.Run(new MouseCursors());
  40.      }
  41.      public MouseCursors()
  42.      {
  43.           Text = "Cursores del rat≤n";
  44.           BackColor = SystemColors.Window;
  45.           ForeColor = SystemColors.WindowText;
  46.           ResizeRedraw = true;
  47.      }
  48.      protected override void OnMouseMove(MouseEventArgs mea)
  49.      {
  50.           int x = Math.Max(0, Math.Min(3, mea.X / (ClientSize.Width  / 4)));
  51.           int y = Math.Max(0, Math.Min(6, mea.Y / (ClientSize.Height / 7)));
  52.  
  53.           Cursor.Current = acursor[4 * y + x];
  54.      }
  55.      protected override void OnPaint(PaintEventArgs pea)
  56.      {
  57.           Graphics     grfx   = pea.Graphics;
  58.           Brush        brush  = new SolidBrush(ForeColor);
  59.           Pen          pen    = new Pen(ForeColor);
  60.           StringFormat strfmt = new StringFormat();
  61.  
  62.           strfmt.LineAlignment = strfmt.Alignment = StringAlignment.Center;
  63.  
  64.           for (int y = 0; y < 7; y++)
  65.           for (int x = 0; x < 4; x++)
  66.           {
  67.                Rectangle rect = Rectangle.FromLTRB(
  68.                                          x      * ClientSize.Width  / 4,
  69.                                          y      * ClientSize.Height / 7,
  70.                                         (x + 1) * ClientSize.Width  / 4,
  71.                                         (y + 1) * ClientSize.Height / 7);
  72.  
  73.                grfx.DrawRectangle(pen, rect);
  74.                grfx.DrawString(astrCursor[4 * y + x], 
  75.                                Font, brush, rect, strfmt);
  76.           }
  77.      }
  78. }
  79.